package day19;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 复制一张图片
 * 
 * @author wangbiao
 * 
 */
public class CopyImageFile {

	public static void main(String[] args) {
		FileInputStream fis = null;
		FileOutputStream fos = null;
		try {
			fis = new FileInputStream("400.jpg");
			fos = new FileOutputStream("520.jpg");
			byte[] buf = new byte[1024];
			int len = 0;
			while ((len = fis.read(buf)) != -1) {
				fos.write(buf, 0, len);
			}
		} catch (FileNotFoundException e) {
			throw new RuntimeException("未找到要操作的文件！");
		} catch (IOException e) {
			throw new RuntimeException("文件读写失败！");
		} finally {
			if (null != fis) {
				try {
					fis.close();
				} catch (IOException e) {
					throw new RuntimeException("字节读取流关闭失败！");
				} finally {
					if (null != fos) {
						try {
							fos.close();
						} catch (IOException e) {
							throw new RuntimeException("字节写入流关闭失败！");
						}
					}
				}
			}
		}
	}
}
